package by.bsu.fami.greyscalecodefrontend.activities;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import by.bsu.fami.greyscalecodefrontend.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;

public class HelpActivity extends Activity {
	private static final String TAG = "HelpActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_help);
		WebView webView = (WebView)findViewById(R.id.webView);
		webView.loadData(readTextFromResource(R.raw.help), 
				"text/html", "utf-8");
	}
	
	private String readTextFromResource(int resourceID) {
		InputStream raw = getResources().openRawResource(resourceID);
		ByteArrayOutputStream stream = new ByteArrayOutputStream();
		int i;
		try {
			i = raw.read();
			while (i != -1) {
				stream.write(i);
				i = raw.read();
			}
			raw.close();
		} catch (IOException e) {
			Log.e(TAG, "", e);
		}
		return stream.toString();
	}
}
